import { themes as prismThemes } from 'prism-react-renderer';
import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
import type * as Redocusaurus from 'redocusaurus';
import path from 'path';

// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)

const config: Config = {
  title: '开放原子开源运营专区',
  tagline: '',
  favicon: 'img/favicon.ico',

  // Set the production url of your site here
  url: 'https://community.openatom.cn',
  // Set the /<baseUrl>/ pathname under which your site is served
  // For GitHub pages deployment, it is often '/<projectName>/'
  baseUrl: '/',

  // GitHub pages deployment config.
  // If you aren't using GitHub pages, you don't need these.
  // organizationName: 'facebook', // Usually your GitHub org/user name.
  // projectName: 'docusaurus', // Usually your repo name.

  onBrokenLinks: 'throw',
  onBrokenMarkdownLinks: 'warn',
  scripts: [
    {
      src: 'https://hm.baidu.com/hm.js?f24c3f435222432ee95abff6357902a8',
      async: true,
    },
    {
      src: 'https://openatom.cn/trivial-services/stats/index/entry?id=10',
      async: true,
    },
  ],

  // Even if you don't use internationalization, you can use this field to set
  // useful metadata like html lang. For example, if your site is Chinese, you
  // may want to replace "en" with "zh-Hans".
  i18n: {
    defaultLocale: "zh-CN",
    locales: ["zh-CN"],
    localeConfigs: {
      "zh-CN": {
        htmlLang: "zh-CN",
        label: "简体中文",
      },
    },
  },

  presets: [
    [
      'classic',
      {
        docs: {
          sidebarPath: './sidebars.ts',
          // Please change this to your repo.
          // Remove this to remove the "edit this page" links.
          editUrl:
            'https://atomgit.com/atomgit-open-source-ecosystem/community-www/blob/master',
        },
        blog: {
          showReadingTime: true,
          feedOptions: {
            type: ['rss', 'atom'],
            xslt: true,
          },
          // Please change this to your repo.
          // Remove this to remove the "edit this page" links.
          editUrl:
            'https://atomgit.com/atomgit-open-source-ecosystem/community-www/blob/master',
          // Useful options to enforce blogging best practices
          onInlineTags: 'warn',
          onInlineAuthors: 'warn',
          onUntruncatedBlogPosts: 'warn',
        },
        theme: {
          customCss: './src/css/custom.css',
        },
        sitemap: {
          ignorePatterns: undefined,
          lastmod: null,
          priority: null,
          changefreq: null,
        },
      } satisfies Preset.Options,

    ],
    // Redocusaurus config
    [
      'redocusaurus',
      {
        config: path.join(__dirname, 'redocly.yaml'),
        openapi: {
          path: 'open-api',
          routeBasePath: '/open-api',
        },
        // Plugin Options for loading OpenAPI files
        specs: [
          // Pass it a path to a local OpenAPI YAML file
          {
            // Redocusaurus will automatically bundle your spec into a single file during the build
            spec: 'open-api/index.yaml',
            route: '/open-api/',
          },
          // // You can also pass it a OpenAPI spec URL
          // {
          //   spec: 'https://redocly.github.io/redoc/openapi.yaml',
          //   route: '/openapi/',
          // },
        ],
        // Theme Options for modifying how redoc renders them
        theme: {
          // Change with your site colors
          primaryColor: '#1890ff',
        },
      },
    ] satisfies Redocusaurus.PresetEntry,
  ],

  plugins: [
    './src/plugin/devServer-plugin',
    './src/plugin/router-guard'
  ],
  themes: [
    // ... Your other themes.
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      /** @type {import("@easyops-cn/docusaurus-search-local").PluginOptions} */
      ({
        // ... Your options.
        // `hashed` is recommended as long-term-cache of index file is possible.
        hashed: true,

        // For Docs using Chinese, it is recomended to set:
        language: ["zh"],

        // If you're using `noIndex: true`, set `forceIgnoreNoIndex` to enable local index:
        // forceIgnoreNoIndex: true,
        highlightSearchTermsOnTargetPage: true,
        indexDocs: true,
        indexBlog: true,
        indexPages: true,
        explicitSearchResultPath: true,
        hideSearchBarWithNoSearchContext: true,
      }),
    ],
  ],
  themeConfig: {
    // Replace with your project's social card
    image: 'img/logo.jpg',
    navbar: {
      title: '开放原子开源运营专区',
      logo: {
        alt: '开放原子开源运营专区',
        src: 'img/logo.jpg',
      },
      hideOnScroll: true,
      items: [
        {
          to: 'showcase',
          label: '用户案例',
          position: 'left'
        },
        {
          to: 'https://openatom-dashboard.x-lab.info',
          label: '全球开源协作全景图',
          position: 'left'
        },
        {
          to: 'https://talent.openatom.cn',
          label: '人才评价平台',
          position: 'left'
        },
        {
          to: 'https://ossinsight.atomgit.com/collections',
          label: '项目趋势洞察',
          position: 'left'
        },
        {
          to: 'infrastructure',
          label: '基础设施',
          position: 'left'
        },
        {
          type: 'dropdown',
          position: 'left',
          label: '文档',
          items: [
            {
              label: '产品介绍',
              to: "https://res.oafimg.cn/-/12242c81f4852699/%E5%BC%80%E6%94%BE%E5%8E%9F%E5%AD%90%E5%BC%80%E6%BA%90%E5%9F%BA%E9%87%91%E4%BC%9A%E5%BC%80%E6%BA%90%E8%BF%90%E8%90%A5%E4%B8%93%E5%8C%BA%E4%BB%8B%E7%BB%8D.pdf",
            },
            {
              type: 'doc',
              docId: 'user-guide/user-guide',
              label: '用户手册',
            },
            {
              to: '/open-api/',
              label: '开放接口',
            }
          ]
        },
        {
          to: 'changelog',
          label: '更新动态',
          position: 'left',
        },
      ],
    },
    footer: {
      style: 'dark',
      links: [
        {
          title: '关于我们',
          items: [
            {
              label: '开放原子开源基金会官网',
              to: 'https://openatom.cn',
            },
            {
              label: 'AtomGit 开源协作平台',
              to: 'https://atomgit.com',
            },
            {
              label: '开放原子开源基金会人才评价系统',
              to: 'https://talent.openatom.cn',
            },
            {
              label: '源码仓库',
              to: 'https://atomgit.com/atomgit-open-source-ecosystem/community-www',
            }
          ],
        },
        {
          title: '优秀社区展示',
          items: [
            {
              label: '开源小满 EasyXMen',
              to: 'https://easyxmen.atomgit.com',
            },

            {
              label: '黄鹤开源社区',
              to: 'https://huanghe.atomgit.com',
            },
            {
              label: 'FOSS Legal 开源法律社区',
              to: 'https://legal.atomgit.com/',
            },
            {
              label: '更多',
              to: 'showcase',
            },
          ],
        },
        {
          title: '联系我们',
          items: [
            {
              label: '开通社区',
              to: 'https://survey.atomgit.com/render/NoRneDxR?t=1744190497681',
            },
            {
              label: '项目募集',
              to: 'mailto:foss-project@openatom.org',
            },
            {
              label: '资金捐赠',
              to: 'mailto:sponsorship@openatom.org',
            },
            {
              label: '建议反馈',
              to: 'https://atomgit.com/atomgit_operate/feedback/issues',
            },
          ],
        },
      ],
      copyright: `
      开放原子开源基金会版权所有
      <a href="https://beian.miit.gov.cn/" target="_blank">京ICP备2020036654号-1</a>
      <img src="https://res.oafimg.cn/-/e2468638b6adb4de/police.png" width="16" height="16" class="mx-5px" alt="police" />
      京公网安备 11030102011597 号
      <br/> 
      Built with Docusaurus.`,
    },
    prism: {
      theme: prismThemes.github,
      darkTheme: prismThemes.dracula,
    },
  } satisfies Preset.ThemeConfig,
};

export default config;
